/*
 * Copyright (C) 2010 TTPASI, Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS-IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ttpasi.jgenere.chaocipher.testutils;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

import ttpasi.jgenere.chaocipher.Chaocipher;

// Don't chain assertTranslation calls, so as to exercise each distinct creation steps. 

/**
 * @author Bruce [com.gmail @ ProgrammerBruce]
 */
public class AssertUtils
{
  public static final String LINE_SEPARATOR = System.getProperty("line.separator");

  public static void assertState(Chaocipher chaocipher, String left, String right, int zenith, int nadir)
  {
    assertThat(chaocipher.leftCiphertextAlphabet(), is(left));
    assertThat(chaocipher.rightPlaintextAlphabet(), is(right));
    assertThat(chaocipher.zenith(), is(zenith));
    assertThat(chaocipher.nadir(), is(nadir));
  }

  public static void assertState(Chaocipher chaocipher, String left, String right, int nadir)
  {
    assertThat(chaocipher.leftCiphertextAlphabet(), is(left));
    assertThat(chaocipher.rightPlaintextAlphabet(), is(right));
    assertThat(chaocipher.nadir(), is(nadir));
  }

  public static void assertState(Chaocipher chaocipher, String left, String right)
  {
    assertThat(chaocipher.leftCiphertextAlphabet(), is(left));
    assertThat(chaocipher.rightPlaintextAlphabet(), is(right));
  }

  public static void assertEncipher(String leftCiphertextAlphabet, String rightPlaintextAlphabet,
      String plaintextMessage, String ciphertextMessageExpected, boolean byrnePunctuation, int blockSize, int lineLength)
  {
    Chaocipher chaocipher = new Chaocipher(leftCiphertextAlphabet, rightPlaintextAlphabet);
    String ciphertextMessage = chaocipher.encipher(plaintextMessage, byrnePunctuation, blockSize, lineLength);
    assertState(chaocipher, leftCiphertextAlphabet, rightPlaintextAlphabet);
    assertThat(ciphertextMessage, is(ciphertextMessageExpected));
  }

  public static void assertEncipher(String leftCiphertextAlphabet, String rightPlaintextAlphabet,
      String plaintextMessage, String ciphertextMessageExpected, boolean byrnePunctuation, int blockSize)
  {
    Chaocipher chaocipher = new Chaocipher(leftCiphertextAlphabet, rightPlaintextAlphabet);
    String ciphertextMessage = chaocipher.encipher(plaintextMessage, byrnePunctuation, blockSize);
    assertState(chaocipher, leftCiphertextAlphabet, rightPlaintextAlphabet);
    assertThat(ciphertextMessage, is(ciphertextMessageExpected));
  }

  public static void assertEncipher(String leftCiphertextAlphabet, String rightPlaintextAlphabet,
      String plaintextMessage, String ciphertextMessageExpected, int blockSize)
  {
    Chaocipher chaocipher = new Chaocipher(leftCiphertextAlphabet, rightPlaintextAlphabet);
    String ciphertextMessage = chaocipher.encipher(plaintextMessage, blockSize);
    assertState(chaocipher, leftCiphertextAlphabet, rightPlaintextAlphabet);
    assertThat(ciphertextMessage, is(ciphertextMessageExpected));
  }

  public static void assertEncipher(String leftCiphertextAlphabet, String rightPlaintextAlphabet,
      String plaintextMessage, String ciphertextMessageExpected, boolean byrnePunctuation)
  {
    Chaocipher chaocipher = new Chaocipher(leftCiphertextAlphabet, rightPlaintextAlphabet);
    String ciphertextMessage = chaocipher.encipher(plaintextMessage, byrnePunctuation);
    assertState(chaocipher, leftCiphertextAlphabet, rightPlaintextAlphabet);
    assertThat(ciphertextMessage, is(ciphertextMessageExpected));
  }

  public static void assertEncipher(String leftCiphertextAlphabet, String rightPlaintextAlphabet,
      String plaintextMessage, String ciphertextMessageExpected)
  {
    Chaocipher chaocipher = new Chaocipher(leftCiphertextAlphabet, rightPlaintextAlphabet);
    String ciphertextMessage = chaocipher.encipher(plaintextMessage);
    assertState(chaocipher, leftCiphertextAlphabet, rightPlaintextAlphabet);
    assertThat(ciphertextMessage, is(ciphertextMessageExpected));
  }

  public static void assertDecipher(String leftCiphertextAlphabet, String rightPlaintextAlphabet,
      String plaintextMessageExpected, String ciphertextMessage)
  {
    Chaocipher chaocipher = new Chaocipher(leftCiphertextAlphabet, rightPlaintextAlphabet);
    String plaintextMessage = chaocipher.decipher(ciphertextMessage);
    assertState(chaocipher, leftCiphertextAlphabet, rightPlaintextAlphabet);
    assertThat(plaintextMessage, is(plaintextMessageExpected));
  }

  public static void assertEncipher(String leftCiphertextAlphabet, String rightPlaintextAlphabet, int zenith,
      int nadir, String plaintextMessage, String ciphertextMessageExpected)
  {
    Chaocipher chaocipher = new Chaocipher(leftCiphertextAlphabet, rightPlaintextAlphabet, zenith, nadir);
    String ciphertextMessage = chaocipher.encipher(plaintextMessage);
    assertState(chaocipher, leftCiphertextAlphabet, rightPlaintextAlphabet, zenith, nadir);
    assertThat(ciphertextMessage, is(ciphertextMessageExpected));
  }

  public static void assertDecipher(String leftCiphertextAlphabet, String rightPlaintextAlphabet, int zenith,
      int nadir, String ciphertextMessage, String plaintextMessageExpected)
  {
    Chaocipher chaocipher = new Chaocipher(leftCiphertextAlphabet, rightPlaintextAlphabet, zenith, nadir);
    String plaintextMessage = chaocipher.decipher(ciphertextMessage);
    assertState(chaocipher, leftCiphertextAlphabet, rightPlaintextAlphabet, zenith, nadir);
    assertThat(plaintextMessage, is(plaintextMessageExpected));
  }

  public static void assertEncipher(String leftCiphertextAlphabet, String rightPlaintextAlphabet, int nadir,
      String plaintextMessage, String ciphertextMessageExpected)
  {
    Chaocipher chaocipher = new Chaocipher(leftCiphertextAlphabet, rightPlaintextAlphabet, nadir);
    String ciphertextMessage = chaocipher.encipher(plaintextMessage);
    assertState(chaocipher, leftCiphertextAlphabet, rightPlaintextAlphabet, nadir);
    assertThat(ciphertextMessage, is(ciphertextMessageExpected));
  }

  public static void assertDecipher(String leftCiphertextAlphabet, String rightPlaintextAlphabet, int nadir,
      String ciphertextMessage, String plaintextMessageExpected)
  {
    Chaocipher chaocipher = new Chaocipher(leftCiphertextAlphabet, rightPlaintextAlphabet, nadir);
    String plaintextMessage = chaocipher.decipher(ciphertextMessage);
    assertState(chaocipher, leftCiphertextAlphabet, rightPlaintextAlphabet, nadir);
    assertThat(plaintextMessage, is(plaintextMessageExpected));
  }
}